package com.atguigu.gmall.juc;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author 陈昆昆
 * @version 1.0
 * @date 2020/5/31 21:53
 */
public class KcrSuo {
    static  ReentrantLock reentrantLock = new ReentrantLock();


    public static void stark() {
        reentrantLock.lock();
        try{
            System.out.println(Thread.currentThread().getName()+"正在预定票");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"完成购票");
        }finally {
            reentrantLock.unlock();
        }
    }

    public static void main(String[] args) {
        new Thread(()->stark()).start();
        new Thread(()->stark()).start();
        new Thread(()->stark()).start();
        new Thread(()->stark()).start();
    }
}
